package com.aerors.DataProcess;

import org.gdal.ogr.DataSource;
import org.gdal.ogr.Feature;
import org.gdal.ogr.FeatureDefn;
import org.gdal.ogr.FieldDefn;
import org.gdal.ogr.Layer;
import org.gdal.ogr.ogr;

public class TestGDALVectorEdit {

	private static final String shpPath = "C:\\data\\shapes\\sjy4326.shp";
	private static final long fid = 120l;
	public static void main(String[] args) {
		
		ogr.RegisterAll();
		
		DataSource ds = ogr.Open(shpPath);
		
		Layer layer = ds.GetLayer(0);
		long count = layer.GetFeatureCount();
		
		FeatureDefn featureDefn = layer.GetLayerDefn();
		
//		for(int i=0;i<featureDefn.GetFieldCount();i++) {
//			FieldDefn fieldDefn = featureDefn.GetFieldDefn(i);
//			System.out.println(fieldDefn.GetName() + ";" + fieldDefn.GetFieldType());
//		}
		
		Feature feature = layer.GetFeature(fid);
		
		//原始值
		long oldValue = feature.GetFieldAsInteger64("SJY2005_ID");
		System.out.println("oldValue:" + oldValue);
		
//		int index = featureDefn.GetFieldIndex("SJY2005_ID");
//		long alterValue = 999l;
//		feature.SetFieldInteger64(index, alterValue);
//		
//		//修改后的值
//		long newValue = feature.GetFieldAsInteger64("SJY2005_ID");
//		System.out.println(newValue);
//		System.out.println("newValue:" + newValue);
	}
}
